package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.core.utils.RequestUtil;
import com.weixing.mall.provider.mapper.BannerMapper;
import com.weixing.mall.provider.model.domain.Banner;
import com.weixing.mall.provider.model.dto.cms.BannerDto;
import com.weixing.mall.provider.model.enums.cms.BannerLocEunm;
import com.weixing.mall.provider.model.enums.cms.BannerTypeEunm;
import com.weixing.mall.provider.model.query.BannerQuery;
import com.weixing.mall.provider.model.vo.cms.BannerVo;
import com.weixing.mall.provider.service.IBannerService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ClassName BannerServiceImpl
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/7/26
 * @Version 1.0
 **/
/**
 * <p>
 * 轮播图表 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-18
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements IBannerService {


    @Override
    public IPage<BannerVo> selectOfPage(Page page, BannerQuery bannerQuery) {
        return baseMapper.selectListOfPage(page,bannerQuery);
    }

    @Override
    public void save(BannerDto bannerDto) {
        Banner banner = new Banner();
        BeanUtils.copyProperties(bannerDto,banner);
        banner.setIsEnable(bannerDto.getIsEnable().getValue());
        banner.setBannerLoc(bannerDto.getBannerLoc().getValue());
        banner.setBannerType(bannerDto.getBannerType().getValue());
        if (null == bannerDto.getId()){
            save(banner);
        }else{
            banner.setUpdatedTime(new Date());
            updateById(banner);
        }
    }

    @Override
    public void deleteAll(int[] ids) {
        baseMapper.delAll(ids);
    }

    @Override
    public BannerVo getBannerById(long id) {
        return baseMapper.getBannerById(id);
    }

    @Override
    public List<BannerVo> selectListByType(BannerLocEunm bannerLoc, BannerTypeEunm banner) {
        return baseMapper.selectListByType(bannerLoc.getValue(),banner.getValue());
    }


}
